package prodcon;

public class CircularBuffer2 implements Buffer {
	private static final int MAX_SIZE = 8;
	private int base = 0;
	private int[] circBuffer = new int[MAX_SIZE];
	private int size = 0;
	
	synchronized public int getValueFromBuffer() {
		int index = base;
		base = (base + 1) % MAX_SIZE;
		size--;
		return circBuffer[index];
	}

	synchronized public void putValueIntoBuffer(int value) {
		int index = (base + size) % MAX_SIZE;
		circBuffer[index] = value;
		size++;
	}

	public int get() { return getValueFromBuffer(); }
	
	public void put(int value) { putValueIntoBuffer(value); }
}
